/**
 * Created by dengchao on 2016/4/7.
 */

(function ($){
    $(document).on("scroll",function (){
        //alert(1);
        var sT=$(document).scrollTop();
        if(sT<=30){
            $("#pageheader div").css({
                color:"white"
            });
            $("#pageheader div a").css({
                color:"white"
            });
            $("#pageheader").css({
                backgroundColor:"transparent"
            })
        }else{
            $("#pageheader div").css({
                color:"black"
            });
            $("#pageheader div a").css({
                color:"black"
            });
            $("#pageheader").css({
                backgroundColor:"white"
            })
        }
    });

    /*请求数据库*/
    var myapp=angular.module("myApp",[]);
    /*添加事件*/
    myapp.controller("biaoti",function ($scope,$location){
        $scope.myurl=$location.absUrl();
        //console.log($scope.myurl);
        var arr=$scope.myurl.split("=");
        //console.log(arr[1]);
        if(arr[1]==1){
            //console.log("吃货大赛20强");
            $scope.mysrc="../images/public/9.jpg";
            $scope.mytitle="吃货必推荐来成都必吃人气餐厅"
        }else if(arr[1]==2){
            //console.log("成都日料十强");
            $scope.mysrc="../images/public/9.jpg";
            $scope.mytitle="鲜粉最爱，总有一家日料是你的菜"
        }else if(arr[1]==3){
            //console.log("成都获取十强");
            $scope.mysrc="../images/public/9.jpg";
            $scope.mytitle="2015年成都火锅十强终于揭晓了！，快来看看你的喜爱的火锅店上榜没有。"
        }else{
            //console.log("成都苍蝇馆子");
            $scope.mysrc="../images/public/9.jpg";
            $scope.mytitle="味道好、环境差、性价比高，这是一批真正能代表老成都味道的馆子"
        }
    });
    myapp.controller("myctr",function ($scope,$http,$location){
        $scope.myurl=$location.absUrl();
        var arr=$scope.myurl.split("=");
        //console.log(arr[1]);
        $scope.Cause=function(){
            $http.post("myctr.do",{myid:arr[1]}).success(function (data){
                //console.log(data);
                var myarr=[];
                for(var i=0; i<data.length;i++){
                    var mydata = data[i].shop_address.split("-",1);
                    myarr.push(mydata);
                    data[i].shop_address=myarr[i];
                }
                var myjson={"sort":data};
                //console.log(myjson);
                /*更具数组中的赞的到小从大到小进行排序*/
                myjson["sort"].sort(function (a,b){
                   return a["parise_number"]<b["parise_number"] ? 1 :(a["parise_number"]==b["parise_number"] ? 0 : -1)
                });
                //console.log(myjson.sort);
                $scope.xiangqing=myjson["sort"];
                //console.log($scope.xiangqing)
            })
        };
    });
    myapp.directive("myclick",function ($http){
        return function (scope,element,attrs){
            //console.log(element);
            element.bind('click',function(){
                //console.log(1);
                var zanshu=element.addClass();
                //console.log(zanshu);
                //console.log(element.parent().parent().find("hgroup"));
                if(zanshu.hasClass("figcaption_span2change")){
                    console.log(2);
                    /*给用户一个提示信息，已经点过赞了*/


                }else{
                    element.addClass('figcaption_span2change');
                    element.find("i").text(parseInt(element.find("i").text())+1);
                    var parise_number=element.find("i").text();
                    //console.log(parise_number);
                    /*向服务器发起请求，更新添加的数据*/
                    //获取到图片的名字
                    var tupian_name=element.parent().parent().find("hgroup").text();
                    //发起请求
                    $http.post("dianzan.do",{tupian:tupian_name,parise_number:parise_number}).success(function (data){
                        /*成功返回数据*/
                        //console.log(1);
                        console.log(data);
                    })
                }
                //element.html();
                //console.log(element.find("i").text());
                //console.log(parseInt(element.find("i").text())+1);
            })
        }
    });


})(jQuery);